package net.yunzhanyi.client.utils;


import net.yunzhanyi.client.constant.AccountConstant;
import net.yunzhanyi.client.domain.dto.ClientLoginUser;
import net.yunzhanyi.common.core.utils.ObjectUtils;
import net.yunzhanyi.common.web.util.ServletUtils;

/**
 * @author qiuxin
 * @code AuthUtil
 * @date 2022/3/29
 * description：
 */
public class AuthUtils {

    public static long getAid() {
        Object aid = ServletUtils.getAttribute(AccountConstant.AUTH);
        if (ObjectUtils.isNull(aid)) {
            return -1;
        }
        return Long.parseLong(aid.toString());
    }
    public static long getUid() {
        Object uid = ServletUtils.getAttribute(AccountConstant.USER);
        if (ObjectUtils.isNull(uid)) {
            return -1;
        }
        return Long.parseLong(uid.toString());
    }

    public static ClientLoginUser getLoginUser(){
        return (ClientLoginUser) ServletUtils.getAttribute(AccountConstant.LOGIN_USER);
    }
    public static String getRedisTokenKey() {
        Object redisTokenKey = ServletUtils.getAttribute(AccountConstant.RTK);
        if (ObjectUtils.isNull(redisTokenKey)) {
            return "";
        }
        return redisTokenKey.toString();
    }
}
